#define SID(x) 1

#include "File.h"
#include "Console.h"
#include "FileSystem.h"
#include "MemoryManager.h"
#include "Hashing.h"
#include "StringManager.h"
#include "Constants.h"

#include <conio.h>

using namespace CEngine;


///This program scans the entire project's source code before it is compiled.
///The input_file is what is about to be compiled.
///The output_file is where hashed strings are saved to be loaded by the string manager.
int main(int argc, char* argv[])
{
    if(argc != 3) {
        Console::print("Usage: PreCompileProcessor.exe input_file output_file\n");
        return 0;
    }

    MemoryManager::initialize();
    FileSystem::initialize();
    StringManager::customInitialize();

    FilePath inputPath(argv[1]);
    FilePath outputPath(argv[2]);

    if(!inputPath.pathExists()) {
        Console::print("%q%s does not exist.\n%r", Console::LRED, inputPath.getFullPath());
        Console::print("Hit any key to exit.\n");
        while(true) {
            if(kbhit()) {
                break;
            }
        }
        MemoryManager::shutdown();
        return 1;
    }

    CHAR backupFilePath[261];
    for (U32 i = 0; i < inputPath.getLength(); ++i) {
        backupFilePath[i] = inputPath.getFullPath()[i];
    }
    backupFilePath[inputPath.getLength()] = '.';
    backupFilePath[inputPath.getLength() + 1] = 'B';
    backupFilePath[inputPath.getLength() + 2] = '\0';

    if(!FileSystem::copy(inputPath, backupFilePath)) {
        Console::print("%q%s could not be created.\n%r", Console::LRED, backupFilePath);
        Console::print("Hit any key to exit.\n");
        while(true) {
            if(kbhit()) {
                break;
            }
        }
        MemoryManager::shutdown();
        return 1;
    }


}
